from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        
        #题目出现
      
        text2 = Tex(r"\text{(2016年)设函数}$f\left( x\right) $\text{满足方程}$y''+2y'+ky=0( 0 <k < 1) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        text20 = Tex(r"\text{(1)证明:反常积分}$\int _{0}^{+\infty }y\left( x\right) dx$\text{收敛}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,20,0])
        text200 = Tex(r"\text{(2)若}$y\left( 0\right) =1,y'\left( 0\right) =1,$\text{求}$\int _{0}^{+\infty }y\left( x\right) dx$\text{的值}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,15,0])
        





        
        self.play(Create(text2),Create(text20),Create(text200))
        
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)


        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=24,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-7.5,15,0])
        self.play(Create(rectangle))

        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([12.5,15,0])
        self.play(Create(rectangle1))

        text3 = Tex(r"$\int _{0}^{+\infty }y\left( x\right) dx=-\dfrac{c_{1}}{\lambda _{1}}-\dfrac{c_{2}}{\lambda _{2}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-7.5,10,0])
        text4 = Tex(r"\text{(确定常数}$c_{1},c_{2},\lambda _{1},\lambda _{2}$\text{)}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text3,RIGHT,buff=2)
        self.play(
            ReplacementTransform(rectangle,text3),
            
        
        )
        self.play(
           
            ReplacementTransform(rectangle1,text4),
            
        
        )


        text5 = Tex(r"$y\left( x\right) =c_{1}e^{\lambda _{1}x}+c_{2}e^{\lambda _{2}x}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,5,0])
        self.play(Create(text5))
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=24,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-7.5,15,0])
        self.play(Create(rectangle))
        text6 = Tex(r"$c_{1}+c_{2}=1,c_{1}\lambda _{1}+c_{2}\lambda _{2}=1$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        self.play(
            ReplacementTransform(rectangle,text6),
            ReplacementTransform(text5,text6),
            
        
        )
        text7 = Tex(r"$\lambda _{1}+\lambda _{2}=-1,\lambda _{1}\lambda _{2}=k$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,0,0])
        self.play(Create(text7))
        arrow = Arrow(start=[-5,2.5,0],end=[5,2.5,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow))

        text8 = Tex(r"$\int _{0}^{+\infty }y\left( x\right) dx=\dfrac{3}{k}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,2.5,0])
        self.play(Create(text8))
        self.wait(0.2)
        #下划线
        #下划线
        dot1=Dot([-40,-5,0])
        dot2=Dot([40,-5,0])
        line=Line(dot1,dot2).set_color(PURPLE)
        line.set_stroke(width=30)  # 设置宽度为 30
        self.play(Create(line))
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=24,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([10,25,0])
        self.play(Create(rectangle))
        text9 = Tex(r"$\int _{0}^{+\infty }y''\left( x\right) dx+2\int _{0}^{+\infty }y'\left( x\right) dx+k\int _{0}^{+\infty }y\left( x\right) dx=0$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-15,0])
        self.play(
            ReplacementTransform(rectangle,text9),
            
        
        )
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([17.5,-15,0])
        self.play(Create(rectangle))
        self.play(FadeOut(rectangle))
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([-2.5,-15,0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([-23,-15,0])
        self.play(Create(rectangle1),Create(rectangle2))
        text10 = Tex(r"$\left[ y'\left( +\infty \right) -y'\left( 0\right) \right] +2\left[ y\left( +\infty \right) -y\left( 0\right) \right] +k\int _{0}^{+\infty }y\left( x\right) dx=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-15,0])
        self.play(
            ReplacementTransform(text9,text10),
            ReplacementTransform(rectangle2,text10),
            ReplacementTransform(rectangle1,text10),
        
        )

        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([20,-15,0])
        rectangle0=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle0.move_to([20,-15,0])
        text11 = Tex(r"\text{积分问题}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-20,0])
        self.play(Create(rectangle),Create(rectangle0),Create(text11))
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([-28.5,-15,0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([-5,-15,0])
        arrow10 = Arrow(start=[10,-20,0],end=[-10,-20,0],color=BLUE
                       , stroke_width=20, tip_length=1)

        text12 = Tex(r"\text{极限问题}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-18,-20,0])
        self.play(
            
            ReplacementTransform(rectangle,rectangle2),
            ReplacementTransform(rectangle0,rectangle1),
            GrowArrow(arrow10),Create(text12)
        
        )
        text13 = Tex(r"\text{极限}",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-5,0])
        self.play(Create(text13))
        text14 = Tex(r"\text{求导}",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-5,0])
        self.play(Create(text14))
        text15 = Tex(r"\text{积分}",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-5,0])
        self.play(Create(text15))
        self.play(FadeOut(text15,text14,text13,text12,text11,arrow10))

        text16 = Tex(r"$y=c_{1}e^{\lambda _{1}x}+c_{2}e^{\lambda _{2}x}$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-9,0])
        
        text160 = Tex(r"$\lambda _{1},\lambda _{2} <0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text16,RIGHT,buff=2)
        self.play(Create(text16))
        self.play(Create(text160))
        text17 = Tex(r"$0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-27.5,-20,0])
        text18 = Tex(r"$0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-20,0])
        self.play(
            
            ReplacementTransform(text16,text17),
            ReplacementTransform(text160,text18),
            
        )
        text19 = Tex(r"$1$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-16,-20,0])
        text20 = Tex(r"$1$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-20,0])
        self.play(Create(text19),Create(text20))
        text21 = Tex(r"$\dfrac{3}{k}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-20,0])
        self.play(Create(text21))



        self.wait()